home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / uconv / nsEncoderDecoderUtils.h next >
C/C++ Source or Header  |  2006-05-08  |  9KB  |  165 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is character set conversion utility macros.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corp.
  19.  * Portions created by the Initial Developer are Copyright (C) 2003
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *  Alec Flett <alecf@flett.org>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. #ifndef nsEncoderDecoderUtils_h__
  40. #define nsEncoderDecoderUtils_h__
  41.  
  42. #define NS_ERROR_UCONV_NOCONV \
  43.   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x01)
  44.  
  45. #define NS_SUCCESS_USING_FALLBACK_LOCALE \
  46.   NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_UCONV, 0x02)
  47.  
  48. #define NS_UNICODEDECODER_NAME "Charset Decoders"
  49. #define NS_UNICODEENCODER_NAME "Charset Encoders"
  50.  
  51. #define NS_DATA_BUNDLE_CATEGORY     "uconv-charset-data"
  52. #define NS_TITLE_BUNDLE_CATEGORY    "uconv-charset-titles"
  53.  
  54. struct nsConverterRegistryInfo {
  55.   PRBool isEncoder;             // PR_TRUE = encoder, PR_FALSE = decoder
  56.   const char *charset;
  57.   nsCID cid;
  58. };
  59.  
  60. #define NS_CONVERTER_REGISTRY_START \
  61.   static const nsConverterRegistryInfo gConverterRegistryInfo[] = {
  62.  
  63. #define NS_CONVERTER_REGISTRY_END \
  64.   };
  65.  
  66.  
  67. #define NS_IMPL_NSUCONVERTERREGSELF                                     \
  68. static NS_IMETHODIMP                                                    \
  69. nsUConverterRegSelf(nsIComponentManager *aCompMgr,                      \
  70.                     nsIFile *aPath,                                     \
  71.                     const char* registryLocation,                       \
  72.                     const char* componentType,                          \
  73.                     const nsModuleComponentInfo *info)                  \
  74. {                                                                       \
  75.   nsresult rv;                                                          \
  76.   nsCOMPtr<nsICategoryManager> catman =                                 \
  77.     do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);                  \
  78.   if (NS_FAILED(rv)) return rv;                                         \
  79.                                                                         \
  80.   nsXPIDLCString previous;                                              \
  81.   PRUint32 i;                                                           \
  82.   for (i=0; i<sizeof(gConverterRegistryInfo)/sizeof(gConverterRegistryInfo[0]); i++) { \
  83.     const nsConverterRegistryInfo* entry = &gConverterRegistryInfo[i];         \
  84.     const char *category;                                               \
  85.     const char *key;                                                    \
  86.                                                                         \
  87.     if (entry->isEncoder) {                                             \
  88.       category = NS_UNICODEENCODER_NAME;                                \
  89.     } else {                                                            \
  90.       category = NS_UNICODEDECODER_NAME;                                \
  91.     }                                                                   \
  92.     key = entry->charset;                                               \
  93.                                                                         \
  94.     rv = catman->AddCategoryEntry(category, key, "",                    \
  95.                                   PR_TRUE,                              \
  96.                                   PR_TRUE,                              \
  97.                                   getter_Copies(previous));             \
  98.   }                                                                     \
  99.   return rv;                                                            \
  100. } \
  101. static NS_IMETHODIMP \
  102. nsUConverterUnregSelf(nsIComponentManager *aCompMgr,                        \
  103.                       nsIFile *aPath,                                       \
  104.                       const char*,                                          \
  105.                       const nsModuleComponentInfo *info)                    \
  106. { \
  107.   nsresult rv;                                                          \
  108.   nsCOMPtr<nsICategoryManager> catman =                                 \
  109.   do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);                    \
  110.   if (NS_FAILED(rv)) return rv;                                         \
  111.                                                                         \
  112.   nsXPIDLCString previous;                                              \
  113.   PRUint32 i;                                                           \
  114.   for (i=0; i<sizeof(gConverterRegistryInfo)/sizeof(gConverterRegistryInfo[0]); i++) { \
  115.     const nsConverterRegistryInfo* entry = &gConverterRegistryInfo[i];         \
  116.     const char *category;                                               \
  117.     const char *key;                                                    \
  118.                                                                         \
  119.     if (entry->isEncoder) {                                             \
  120.       category = NS_UNICODEDECODER_NAME;                                \
  121.     } else {                                                            \
  122.       category = NS_UNICODEENCODER_NAME;                                \
  123.     }                                                                   \
  124.     key = entry->charset;                                               \
  125.                                                                         \
  126.     char * value = entry->cid.ToString();                               \
  127.                                                                         \
  128.     rv = catman->DeleteCategoryEntry(category, key, PR_TRUE);           \
  129.     CRTFREEIF(value);                                                   \
  130.   }                                                                     \
  131.   return rv;                                                            \
  132. }
  133.  
  134.  
  135. #define NS_UCONV_REG_UNREG_DECODER(_Charset, _CID)          \
  136.   {                                                         \
  137.     PR_FALSE,                                                \
  138.     _Charset,                                               \
  139.     _CID,                                                   \
  140.   },
  141.   
  142. #define NS_UCONV_REG_UNREG_ENCODER(_Charset, _CID)          \
  143.   {                                                         \
  144.     PR_TRUE,                                               \
  145.     _Charset,                                               \
  146.     _CID,                                                   \
  147.   }, 
  148.  
  149.   // this needs to be written out per some odd cpp behavior that
  150.   // I could not work around - the behavior is document in the cpp
  151.   // info page however, so I'm not the only one to hit this!
  152. #define NS_UCONV_REG_UNREG(_Charset, _DecoderCID, _EncoderCID) \
  153.   {                                                         \
  154.     PR_FALSE,                                               \
  155.     _Charset,                                               \
  156.     _DecoderCID,                                            \
  157.   },                                                        \
  158.   {                                                         \
  159.     PR_TRUE,                                                \
  160.     _Charset,                                               \
  161.     _EncoderCID,                                            \
  162.   },
  163.   
  164. #endif
  165.